﻿/*
 * Author ：步尘
 * CreatDate ：2019/9/17 12:58:56
 * CLR Version ：4.0.30319.42000
 */
namespace WimMain.Fun.Askform
{
    using System.Data;
    using WimMain.Common;
    using WimMain.Models;
    using System.Collections.Generic;

    /// <summary>
    /// Askform
    /// </summary>
    public class BaseAsk : BaseFun
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="contentStr"></param>
        public BaseAsk(string contentStr) : base(contentStr)
        {
            this.ContentStringList = new List<KeyVal>
            {
                new KeyVal("Demo1", "Data Source=127.0.0.1;Initial Catalog=Demo;uid=sa;pwd=123456;"),
                new KeyVal("Demo2", "Data Source=127.0.0.1;Initial Catalog=Demo;uid=sa;pwd=123456;")
            };
        }

        /// <summary>
        /// 用户编号
        /// </summary>
        public string CompanyID { get; set; }

        /// <summary>
        /// 应用程序编号
        /// </summary>
        public string FormApplicationID { get; set; }

        /// <summary>
        /// 表单编号
        /// </summary>
        public string FormID { get; set; }

        /// <summary>
        /// 报告模板路径
        /// </summary>
        protected string ModelPath { get; set; } = ToolFile.GetAbsolutelyPath(ToolConfig.GetAppSetting("ModelPath"));

        /// <summary>
        /// 返回参数
        /// </summary>
        /// <param name="param">额外参数</param>
        /// <returns></returns>
        protected string GetSqlParam(string param = "")
        {
            string sql = "";
            sql += "Declare @" + nameof(CompanyID) + " bigint = " + CompanyID + "\n";
            sql += "Declare @" + nameof(FormApplicationID) + " bigint = " + FormApplicationID + "\n";
            sql += "Declare @" + nameof(FormID) + " bigint = " + FormID + "\n";

            sql += param + "\n\n";
            return sql;
        }

        /// <summary>
        /// 根据FormID，返回参数
        /// </summary>
        /// <param name="formID"></param>
        /// <returns></returns>
        protected BaseAsk GetParam(long formID)
        {
            string sqlStr = string.Format("SELECT CompanyID,FormApplicationID,FormID FROM AskForm_Form WHERE FormID = {0} AND IsDeleted = 0", formID);

            DataTable dt = DbContent.GetTable(sqlStr);
            if (dt.Rows.Count >= 1)
            {
                BaseAsk bf = new BaseAsk(null);

                bf.CompanyID = dt.Rows[0]["CompanyID"] + "";
                bf.FormApplicationID = dt.Rows[0]["FormApplicationID"] + "";
                bf.FormID = dt.Rows[0]["FormID"] + "";
                return bf;
            }
            return null;
        }

    }
}
